<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function checkUser(){
				if(username1()&&checkPassword()&&password1()&&year()&&month()&&day()){
					return true;
				}
				return false;
			}
			function username1(){
				var username = document.forms[0].username.value;
				
				document.getElementById("usernameMsg").innerHTML = "";
				
				var reg = /^.+$/;
				
				if(!reg.test(username)){
					// alert("登录名不能为空");
					
					document.getElementById("usernameMsg").innerHTML = "登录名不能为空";
					return false;
				}
				return true;
			}
			function checkPassword(){
				var password = document.forms[0].password.value;
				if(password.length == 0 ){
					alert("为输入密码请输入密码");
					return false;
				}
				var reg = /^.{6,}$/;
				if(!reg.test(password)){
					alert("密码不能少于6位");
					return false;
				}
				return true;
			}
			function password1(){
				var password = document.forms[0].password.value;
				var password1 = document.forms[0].password1.value;
				if(password != password1){
					alert("再次输入密码不正确");
					return false;
				}
				return true;
			}
			function year(){
				var year = document.forms[0].year.value;
				var y = year.slice(0,2);
				
				if(year.length == 0){
					alert("请输入年份");
					return false;
				}
				if(isNaN(Number(year))){
					alert("请输入正确的年份")
					return false;
				}
				if(year.length < 4){
					alert("请输入正确的年份")
					return false;
				}
				if(y < 20){
					alert("请输入以20开头的年分");
					return false;
				}
				return true;
			}
			function day(){
				var day = document.forms[0].day.value;
				
				if(day.length == 0){
					alert("请输入日期");
					return false;
				}
				if(!(day >= 1 && day <= 31)){
					alert("请输入日期在1~31之间的数字");
					return false;
				}
				return true;
			}
			function month(){
				var month = document.forms[0].month.value;
				
				if(month == -1){
					alert("请选择月份");
					return false;
				}
				return true;
			}
		</script>
	</head>
	<body>
		<form action="HomeWork.jsp" onsubmit="return checkUser()">
			<table>
				<tr>
					<td>登录名：</td>
					<td>
						<input type="text" name="username" onblur="username1()" />
						<span id="usernameMsg"></span>
					</td>
				</tr>
				<tr>
					<td>密码：</td>
					<td><input type="password" name="password"></td>
				</tr>
				<tr>
					<td>再次输入密码:</td>
					<td><input type="password" name="password1"></td>
				</tr>
				<tr>
					<td>出生日期</td>
					<td>
						<input type="text" name="year" style="width: 40px;" maxlength="4">年
						<select name="month">
							<option value ="-1">[选择月份]</option>
							<option value ="1">1</option>
							<option value ="2">2</option>
							<option value ="3">3</option>
							<option value ="4">4</option>
							<option value ="5">5</option>
						</select>月
						<input type="text" name="day" maxlength="2" style="width: 30px;"/>日
					</td>
					<tr>
					<td>
						<input type="reset" name="" id="" value="重填" />
					</td>
					<td>
						<input type="submit" name="" id="" value="同意以下服务条款,提交注册信息" />
					</td>
				</tr>
			</table>
		</form>
	</body>
</html>
